import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class RopeIntranet {
	public static void main(String[] args) throws IOException {
		BufferedReader rdr = new BufferedReader(new InputStreamReader(System.in));
		try {
			int T = Integer.parseInt(rdr.readLine());
			for(int t = 1; t <= T; t++) {
				int N = Integer.parseInt(rdr.readLine());
				int[] A = new int[N], B = new int[N];
				int num = 0;
				for(int i = 0; i < N; i++) {
					String[] AB = rdr.readLine().split(" ");
					A[i] = Integer.parseInt(AB[0]);
					B[i] = Integer.parseInt(AB[1]);
					for(int j = 0; j < i; j++)
						if(A[j] < A[i] && B[j] > B[i] || A[j] > A[i] && B[j] < B[i])
							num++;
				}
				System.out.println("Case #" + t + ": " + num);
			}
		} finally {
			rdr.close();
		}
	}
}
